#!/usr/bin/env python
# 对transdecoder的 cds进行提取 需要获取最长的 cds 

from Bio import SeqIO

import argparse
import sys


parser = argparse.ArgumentParser(
    description='''transdecoder cds 提取最长的那个
    用法:
    transdecoder_take_longest_cds.py -i longest_orfs.cds -o longest_orf.fa
    由大天才于2021年7月8日创建于浙江农业大学''')

parser.add_argument('-i',
                help='必须给定，输入的exonerate gff3文件 ')


parser.add_argument('-o',
                help='必须给定，输出文件')



args = parser.parse_args()

if not args.i or not args.o:
    parser.print_help()
    sys.exit()



infile = args.i

outfile= args.o


final_dic = {}

for i in SeqIO.parse(infile,'fasta'):



	k = str(i.name).split('.p')

	

	
	item = k[0]
	if item not in final_dic:
		final_dic[item] = str(i.seq)
	else:
		if len(final_dic[item]) < len(str(i.seq)):
			final_dic[item] = str(i.seq)

outhandle = open(outfile,'w')

for i in final_dic:
	outhandle.write('>'+i+'\n')
	outhandle.write(final_dic[i]+'\n')
